<?php
/**
 * Created by b17
 * 2/21/12 8:48 PM
 */

class Zend_View_Helper_Curl extends Zend_View_Helper_Abstract
{
    /**
     * @var Zend_Controller_Request_Abstract
     */
    protected $request;

    public function __construct()
    {
        $this->request = \Zend_Controller_Front::getInstance()->getRequest();
    }

    /**
     * Урл для пагинатора.
     *
     * @param $page
     */
    public function curl($params)
    {
        $this->request = \Zend_Controller_Front::getInstance()->getRequest();
        $action = $this->request->getActionName();
        $controller = $this->request->getControllerName();
        $method = 'get' . $controller . $action;
        if (method_exists($this, $method)) {
            $url = call_user_func(array($this, $method), $params['page']);
        } else {
            $requestParams = $this->request->getParams();
            $requestParams['page'] = $params['page'];
            $url = $this->view->url($requestParams);
        }
        return $url;
    }

    /**
     * Url, если вызван с news controller'a
     */
    private function getNewsIndex($page)
    {
        return $this->view->url(array('page' => $page,
            'column' => $this->request->getParam('column'),
            'order' => $this->request->getParam('order'),
            ), 'news_pag');
    }
}
